/*
 * Created by JFormDesigner on Tue Jun 20 11:08:28 CST 2023
 */

package org.scct.chenhui.frames;

import org.scct.chenhui.utils.Utils;

import java.awt.*;
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

/**
 * @author Administrator
 */
public class FrmAdminMain extends JFrame {
    public static void main(String[] args) {
        FrmAdminMain frmAdminMain = new FrmAdminMain();
        frmAdminMain.setVisible(true);
        long l = System.currentTimeMillis();
        System.out.println(l);

    }
    public FrmAdminMain() {
        initComponents();
        initData();
    }

    private void initData() {
        Dimension screenSize = Utils.getScreenSize();
        int x=(screenSize.width-800)/2;
        int y=(screenSize.height-600)/2;
//        设置窗口的大小和左右的宽度
        setBounds(x,y,800,600);


//        创建显示的各个节点
        DefaultMutableTreeNode systemNode = new DefaultMutableTreeNode("系统管理");
        DefaultMutableTreeNode userNode = new DefaultMutableTreeNode("用户管理");
        DefaultMutableTreeNode bookNode = new DefaultMutableTreeNode("图书管理");
        DefaultMutableTreeNode borrowNode = new DefaultMutableTreeNode("借阅管理");
        DefaultMutableTreeNode publishNode = new DefaultMutableTreeNode("出版社管理");
        DefaultMutableTreeNode typeNode = new DefaultMutableTreeNode("图书类别管理");
        systemNode.add(userNode);
        systemNode.add(bookNode);
        systemNode.add(borrowNode);
        systemNode.add(publishNode);
        systemNode.add(typeNode);

//        初始化树形控件数据模型
        DefaultTreeModel treeModel = new DefaultTreeModel(systemNode);
        tree1.setModel(treeModel);
//        默认情况选中第一项用户管理



        tree1.addTreeSelectionListener(new TreeSelectionListener() {
            @Override
            public void valueChanged(TreeSelectionEvent e) {
                Object node = e.getNewLeadSelectionPath().getLastPathComponent();
                if(node.equals(userNode))
                {
                    System.out.println("用户管理");
                    PnlUserManager pnlUserManager = new PnlUserManager();
                    splitPane1.setRightComponent(pnlUserManager);
                }
                if(node.equals(bookNode))
                {
                    System.out.println("图书管理");
                    PnlBookManager pnlBookManager = new PnlBookManager();
                    splitPane1.setRightComponent(pnlBookManager);
                }
                if(node.equals(borrowNode))
                {
                    System.out.println("借阅管理");
                }
                if(node.equals(publishNode))
                {
                    System.out.println("出版社管理");
                }
                if(node.equals(typeNode))
                {
                    System.out.println("类别管理");
                }
            }
        });
//        默认选择用户管理节点
        tree1.setSelectionRow(1);
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - brightch
        menuBar1 = new JMenuBar();
        menu1 = new JMenu();
        menuItem1 = new JMenuItem();
        menuItem2 = new JMenuItem();
        splitPane1 = new JSplitPane();
        scrollPane1 = new JScrollPane();
        tree1 = new JTree();

        //======== this ========
        setTitle("\u7cfb\u7edf\u7ba1\u7406\u5458\u754c\u9762");
        var contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        //======== menuBar1 ========
        {

            //======== menu1 ========
            {
                menu1.setText("\u8bbe\u7f6e");

                //---- menuItem1 ----
                menuItem1.setText("\u5207\u6362\u7528\u6237");
                menu1.add(menuItem1);

                //---- menuItem2 ----
                menuItem2.setText("\u9000\u51fa");
                menu1.add(menuItem2);
            }
            menuBar1.add(menu1);
        }
        setJMenuBar(menuBar1);

        //======== splitPane1 ========
        {

            //======== scrollPane1 ========
            {
                scrollPane1.setViewportView(tree1);
            }
            splitPane1.setLeftComponent(scrollPane1);
        }
        contentPane.add(splitPane1, BorderLayout.CENTER);
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - brightch
    private JMenuBar menuBar1;
    private JMenu menu1;
    private JMenuItem menuItem1;
    private JMenuItem menuItem2;
    private JSplitPane splitPane1;
    private JScrollPane scrollPane1;
    private JTree tree1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
